export abstract class ShopClass {
    ID: number;
    ShopType: ShopType;
    Name: string;
    Description: string;
    Price: number;
    Icon: string;
    Color: string;
    DirectIncome?: number;
    RandomIncome?: boolean;
    ConsumptionBonus?: number;
    IncomeFromConsumption?: number;//see Pub
    IncomeFromShopCount?: boolean;
    LinkageBonus?: number;
    LinkageBonusTypes?: ShopType[];
    ExtraIncomeFromBonus: number = 0;

    constructor(id: number = -1) {
        this.ID = id;
    }

    GetIncomeDescription(): string {
        if (this.DirectIncome) {
            return `客人光顾时持有者获得 ${this.DirectIncome} 两钱。`;
        }
        if (this.RandomIncome) {
            return "客人光顾时持有者投掷一枚骰子并获得等于投掷结果数值的钱";
        }
        if (this.ConsumptionBonus) {
            return `客人光顾时持有者消费菜单牌的数量增加 ${this.ConsumptionBonus} 张`;
        }
        if (this.IncomeFromConsumption) {
            return `客人光顾时持有者获得本回合消耗菜单牌数量 +${this.IncomeFromConsumption} 的钱`;
        }
        if (this.IncomeFromShopCount) {
            return "客人光顾时持有者获得等同于其拥有的店铺数量的钱";
        }
        return "";
    }

    GetLinkageDescription(): string {
        if (this.LinkageBonus) {
            let bonusTypesString = this.LinkageBonusTypes?.map(bonusType => {
                let shop = ShopType2Instance[bonusType];
                return shop.Icon + shop.Name;
            }).join("、");
            return `该效果在客人光顾${this.Name}时并不会生效，而是当客人光顾持有者的${bonusTypesString}时，该效果会使持有者的每间这类店铺的收入增加 ${this.LinkageBonus} 两钱。`;
        }
        return "";
    }
}

export enum ShopType {
    DivinationShop,
    CujuField,
    BookShop,
    Pub,
    ClothShop,
    Theatre,
    PorcelainShop,
    GamblingHouse,
    SyrupShop,
    Teahouse,
    StorytellingHouse,
    JewelryStore
}

export class DivinationShop extends ShopClass {
    Name = "卦肆";
    ShopType = ShopType.DivinationShop;
    Price = 6;
    Icon = "☯️";
    Color = "#b87a6b";
    RandomIncome = true;
}

export class CujuField extends ShopClass {
    Name = "蹴鞠场";
    ShopType = ShopType.CujuField;
    Description = "世间子弟千般艺，只此风流最夺魁。";
    Price = 6;
    Icon = "⚽";
    Color = "#7c8e9b";
    ConsumptionBonus = 2;
}

export class BookShop extends ShopClass {
    Name = "书坊";
    ShopType = ShopType.BookShop;
    Description = "读书破万卷，下笔如有神。";
    Price = 6;
    Icon = "📚";
    Color = "#c1c3bc";
    DirectIncome = 3;
}

export class Pub extends ShopClass {
    Name = "酒肆";
    ShopType = ShopType.Pub;
    Description = "兰陵美酒郁金香，玉碗盛来琥珀光。";
    Price = 7;
    Icon = "🍶";
    Color = "#8e8990";
    IncomeFromConsumption = 1;
}

export class ClothShop extends ShopClass {
    Name = "绸缎庄";
    Description = "应似天台山上月明前，四十五尺瀑布泉。";
    ShopType = ShopType.ClothShop;
    Price = 7;
    Icon = "✂️";
    Color = "#bba394";
    DirectIncome = 4;
}

export class Theatre extends ShopClass {
    Name = "勾栏瓦肆";
    ShopType = ShopType.Theatre;
    Price = 8;
    Icon = "🪕";
    Color = "#7d9a8c";
    IncomeFromShopCount = true;
}

export class PorcelainShop extends ShopClass {
    Name = "瓷器铺";
    ShopType = ShopType.PorcelainShop;
    Description = "大邑烧瓷轻且坚，扣如哀玉锦城传。";
    Price = 9;
    Icon = "🏺";
    Color = "#c79763";
    DirectIncome = 6;
}

export class GamblingHouse extends ShopClass {
    Name = "关扑铺";
    ShopType = ShopType.GamblingHouse;
    Price = 5;
    Icon = "🎉";
    Color = "#b9a280";
    DirectIncome = 2;
    LinkageBonus = 2;
    LinkageBonusTypes = [ShopType.DivinationShop];
}

export class SyrupShop extends ShopClass {
    Name = "饮子铺";
    ShopType = ShopType.SyrupShop;
    Description = "明冰沃新茗，妙饮夸四筵。<br/>休论水第一，凛然香味全。";
    Price = 5;
    Icon = "🍹";
    Color = "#8ca673";
    DirectIncome = 2;
    LinkageBonus = 2;
    LinkageBonusTypes = [ShopType.GamblingHouse];
}

export class Teahouse extends ShopClass {
    Name = "茶馆";
    ShopType = ShopType.Teahouse;
    Description = "竹下忘言对紫茶, 全胜羽客醉流霞。<br/>尘心洗尽兴难尽, 一树蝉声片影斜。";
    Price = 5;
    Icon = "🫖";
    Color = "#eb9669";
    DirectIncome = 2;
    LinkageBonus = 2;
    LinkageBonusTypes = [ShopType.BookShop];
}

export class StorytellingHouse extends ShopClass {
    Name = "说书场";
    ShopType = ShopType.StorytellingHouse;
    Description = "醒木一方口一张，道尽古今说端详。";
    Icon = "🪭";
    Color = "#68625d";
    Price = 5;
    DirectIncome = 2;
    LinkageBonus = 1;
    LinkageBonusTypes = [ShopType.Teahouse, ShopType.Pub, ShopType.SyrupShop];
}

export class JewelryStore extends ShopClass {
    Name = "首饰铺";
    ShopType = ShopType.JewelryStore;
    Price = 5;
    Icon = "📿";
    Color = "#937b88";
    DirectIncome = 2;
    LinkageBonus = 1;
    LinkageBonusTypes = [ShopType.StorytellingHouse, ShopType.ClothShop, ShopType.PorcelainShop];
}

export function instantiateAllShops(repeat: number = 1, startID: number = 0): ShopClass[] {
    let result: ShopClass[] = [];
    if (repeat > 0) {
        for (let i = 0; i < repeat; i++) {
            result.splice(result.length - 1, 0, new DivinationShop(startID++), new CujuField(startID++), new BookShop(startID++), new Pub(startID++), new ClothShop(startID++), new Theatre(startID++), new PorcelainShop(startID++), new GamblingHouse(startID++), new SyrupShop(startID++), new Teahouse(startID++), new StorytellingHouse(startID++), new JewelryStore(startID++));
        }
    }
    return result;
}

export const ShopType2Instance: Record<ShopType, ShopClass> = {
    [ShopType.DivinationShop]: new DivinationShop(),
    [ShopType.CujuField]: new CujuField(),
    [ShopType.BookShop]: new BookShop(),
    [ShopType.Pub]: new Pub(),
    [ShopType.ClothShop]: new ClothShop(),
    [ShopType.Theatre]: new Theatre(),
    [ShopType.PorcelainShop]: new PorcelainShop(),
    [ShopType.GamblingHouse]: new GamblingHouse(),
    [ShopType.SyrupShop]: new SyrupShop(),
    [ShopType.Teahouse]: new Teahouse(),
    [ShopType.StorytellingHouse]: new StorytellingHouse(),
    [ShopType.JewelryStore]: new JewelryStore()
};